﻿namespace Chameleon.Data
{
	using System;
	using System.Linq;

	/// <summary>
	/// Provides a persistence context for data-bound objects, typically via a database connection.
	/// </summary>
	
	public interface IDepository : IDisposable
	{
		/// <summary>
		/// Inserts an item into the underlying data context and returns a reference to the item.
		/// <para>This will not take effect until a commit is performed.</para>
		/// </summary>
		/// <typeparam name="TEntity">Type of the item to insert into the data context.</typeparam>
		/// <param name="item">Item to insert into the data context.</param>

		TEntity Insert<TEntity>( TEntity item ) where TEntity: class;


		/// <summary>
		/// Attaches a previously disconnected item to the context.
		/// </summary>
		/// <typeparam name="TEntity">Type of the item to attach to the context.</typeparam>
		/// <param name="item">Item to attach to the data context.</param>

		void Attach<TEntity>( TEntity item ) where TEntity: class;


		/// <summary>
		/// Deletes an item from the underlying data context.
		/// <para>This will not take effect until a commit is performed.</para>
		/// </summary>
		/// <typeparam name="TEntity">Type of the item to delete from the data context.</typeparam>
		/// <param name="item">Item to remove from the data context.</param>

		void Delete<TEntity>( TEntity item ) where TEntity: class;


		/// <summary>
		/// Submits any outstanding changes to the underlying data context.
		/// </summary>

		void Submit();
	}
}
